package top.hekun.study.core.visitor.simple;

import org.objectweb.asm.*;

import java.util.Arrays;

/**
 * 〈更改类的接口〉
 *
 * @author: Sakura
 * @date: 2023/5/8
 */
public class MyClassVisitor2 extends ClassVisitor {
    public MyClassVisitor2(int apiVersion, ClassVisitor classWriter) {
        super(apiVersion, classWriter);
    }

    @Override
    public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
        System.out.println("MyClassVisitor2:visit");
        // 获取类继承的接口数 ,构造新的数组
        String[] stringArray = new String[interfaces.length + 1];
        // 复制原接口数据
        System.arraycopy(interfaces, 0, stringArray, 0, interfaces.length);
        // 写入新接口数据
        stringArray[interfaces.length] = "java/util/function/LongSupplier";
        super.visit(version, access, name, signature, superName, stringArray);
    }
    @Override
    public FieldVisitor visitField(int access, String name, String descriptor, String signature, Object value) {
        System.out.println("MyClassVisitor2:visitField -- " + name);
        return super.visitField(access, name, descriptor, signature, value);
    }
    @Override
    public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
        System.out.println("MyClassVisitor2:visitMethod -- " + name + " -- " + descriptor);
        return super.visitMethod(access, name, descriptor, signature, exceptions);
    }

    @Override
    public void visitEnd() {
        System.out.println("MyClassVisitor2:visitEnd");

        super.visitEnd();
    }

}
